package com.chengww.grab_rp.utils

import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.chengww.grab_rp.R

/**
 * Created by chengww on 2/20/21
 * @author chengww
 */
object ToastUtil {
    private var toast: Toast? = null
    fun show(context: Context, message: CharSequence) {
        if (message.isEmpty()) return
        toast?.cancel()
        toast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
        toast?.let {
            val toastView = View.inflate(context, R.layout.layout_toast, null)
            it.view = toastView
            it.setGravity(Gravity.CENTER, 0, 0)
            val errorText = toastView.findViewById<TextView>(R.id.tv_text_toast)
            errorText.text = message
            it.show()
        }
    }
}